package com.baitengsoft.patentapimonitor.api.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baitengsoft.patentapimonitor.api.entity.WebPlatformEntity;
import com.baitengsoft.patentapimonitor.api.model.*;
import com.baitengsoft.patentapimonitor.api.model.dto.*;
import com.baitengsoft.patentapimonitor.api.model.param.SearchApplicantAnalysisParam;
import com.baitengsoft.patentapimonitor.api.model.param.SearchMonSummaryParam;
import com.baitengsoft.patentapimonitor.api.service.*;
import com.baitengsoft.patentapimonitor.common.utils.DateUtils;
import com.baitengsoft.patentapimonitor.common.utils.PageResult;
import com.baitengsoft.patentapimonitor.common.utils.WebExcelUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Chen 2018/1/30
 */
@Service
public class WebExcelExportServiceImpl implements WebExcelExportService {
    @Autowired
    private RptPatentDataAreaService rptPatentDataAreaService;
    @Autowired
    private RptApplicantService rptApplicantService;
    @Autowired
    private PacPatentinfoService pacPatentinfoService;
    @Autowired
    private WebPlatformService webPlatformService;
    @Override
    public List<WebAnalysisExportDto> getWebAnalysisExportDto(List<RptPatentDataAreaInfo> infos) {
        List<WebAnalysisExportDto> infoList = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            RptPatentDataAreaInfo info = infos.get(i-1);
            WebAnalysisExportDto dto =new WebAnalysisExportDto();
            dto.setNum(i);
            dto.setAreaName(info.getAreaName());
            dto.setJan(info.getJan());
            dto.setFeb(info.getFeb());
            dto.setMar(info.getMar());
            dto.setApr(info.getApr());
            dto.setMay(info.getMay());
            dto.setJune(info.getJune());
            dto.setJuly(info.getJuly());
            dto.setAug(info.getAug());
            dto.setSetp(info.getSetp());
            dto.setOct(info.getOct());
            dto.setNov(info.getNov());
            dto.setDec(info.getDec());
            dto.setGoal(info.getGoal());
            dto.setCompletionRate(info.getCompletionRate());
            infoList.add(dto);
        }
        return infoList;
    }

    @Override
    public List<WebYearStatisticInfoDto> getWebYearStatisticInfoDto(List<WebYearStatisticInfo> infos) {
        List<WebYearStatisticInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebYearStatisticInfo info = infos.get(i-1);
            WebYearStatisticInfoDto dto =new WebYearStatisticInfoDto();
            dto.setNum(i);
            dto.setFmcount(info.getFmcount());
            dto.setIncreaseRate(info.getIncreaseRate());
            dto.setYear(info.getYear());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setTotal(info.getTotal());
            dto.setWgsjcount(info.getWgsjcount());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebAreaStatisticInfoDto> getWebAreaStatisticInfoDto(List<WebAreaStatisticInfo> infos) {
        List<WebAreaStatisticInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebAreaStatisticInfo info = infos.get(i-1);
            WebAreaStatisticInfoDto dto =new WebAreaStatisticInfoDto();
            dto.setNum(i);
            dto.setAreaName(info.getAreaName());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setTotal(info.getTotal());
            dto.setWgsjcount(info.getWgsjcount());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebIPCAnalysisInfoDto> getWebIPCAnalysisInfoDto(List<WebIPCAnalysisInfo> infos) {
        List<WebIPCAnalysisInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebIPCAnalysisInfo info = infos.get(i-1);
            WebIPCAnalysisInfoDto dto =new WebIPCAnalysisInfoDto();
            dto.setNum(i);
            dto.setIpcName(info.getIpcName());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setTotal(info.getTotal());
            dto.setWgsjcount(info.getWgsjcount());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebInventorAnalysisInfoDto> getWebInventorAnalysisInfoDto(List<WebInventorAnalysisInfo> infos) {
        List<WebInventorAnalysisInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebInventorAnalysisInfo info = infos.get(i-1);
            WebInventorAnalysisInfoDto dto =new WebInventorAnalysisInfoDto();
            dto.setNum(i);
            dto.setInventorName(info.getInventorName());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setTotal(info.getTotal());
            dto.setWgsjcount(info.getWgsjcount());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebAgencyAnalysisInfoDto> getWebAgencyAnalysisInfoDto(List<WebAgencyAnalysisInfo> infos) {
        List<WebAgencyAnalysisInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebAgencyAnalysisInfo info = infos.get(i-1);
            WebAgencyAnalysisInfoDto dto =new WebAgencyAnalysisInfoDto();
            dto.setNum(i);
            dto.setAgencyName(info.getAgencyName());
            dto.setApplicantCount(info.getApplicantCount());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setTotal(info.getTotal());
            dto.setWgsjcount(info.getWgsjcount());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebApplicantInfoDto> getWebApplicantInfoDto(List<WebApplicantInfo> infos) {
        List<WebApplicantInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebApplicantInfo info = infos.get(i-1);
            WebApplicantInfoDto dto =new WebApplicantInfoDto();
            dto.setApplicantName(info.getApplicantName());
            dto.setAreaName(info.getAreaName());
            dto.setIndustry(info.getIndustry());
            dto.setNum(i);
            dto.setTypeName(info.getTypeName());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setTotal(info.getTotal());
            dto.setWgsjcount(info.getWgsjcount());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebApplicantIndustryInfoDto> getWebApplicantIndustryInfoDto(List<WebApplicantIndustryInfo> infos) {
        List<WebApplicantIndustryInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebApplicantIndustryInfo info = infos.get(i-1);
            WebApplicantIndustryInfoDto dto =new WebApplicantIndustryInfoDto();
            dto.setNum(i);
            dto.setIndustryName(info.getIndustryName());
            dto.setSum(info.getSum());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebApplicantTypeInfoDto> getWebApplicantTypeInfoDto(List<WebApplicantTypeInfo> infos) {
        List<WebApplicantTypeInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebApplicantTypeInfo info = infos.get(i-1);
            WebApplicantTypeInfoDto dto =new WebApplicantTypeInfoDto();
            dto.setNum(i);
            dto.setTypeName(info.getTypeName());
            dto.setApplicantTotal(info.getApplicantTotal());
            dto.setPatTotal(info.getPatTotal());
            dto.setPatPercent(info.getPatPercent());
            dto.setApplicantPercent(info.getApplicantPercent());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebPacPatentInfoDto> getWebPacPatentInfoDto(List<PacPatentInfo> infos) {
        List<WebPacPatentInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            PacPatentInfo info = infos.get(i-1);
            WebPacPatentInfoDto dto =new WebPacPatentInfoDto();
            dto.setNum(i);
            dto.setPatNum(info.getPatNum());
            dto.setPatAppDate(info.getPatAppDate());
            dto.setPatName(info.getPatName());
            dto.setPatTypeName(info.getPatTypeName());
            dto.setApplyPerson(info.getApplyPerson());
            dto.setInventPerson(info.getInventPerson());
            dto.setPatApproveDate(info.getPatApproveDate());
            dto.setLawState(info.getLawState());
            dto.setPatAddressLast(info.getPatAddressLast());
            dto.setAgencyName(info.getAgencyName());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebMonAnalysisInfoDto> getWebMonAnalysisInfoDto(List<WebMonAnalysisInfo> infos) {
        List<WebMonAnalysisInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebMonAnalysisInfo info = infos.get(i-1);
            WebMonAnalysisInfoDto dto =new WebMonAnalysisInfoDto();
            dto.setNum(i);
            dto.setAreaName(info.getAreaName());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setWgsjcount(info.getWgsjcount());
            dto.setTotal(info.getTotal());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebMonInvalidAnalysisInfoDto> getWebMonInvalidAnalysisInfoDto(List<WebMonInvalidAnalysisInfo> infos) {
        List<WebMonInvalidAnalysisInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebMonInvalidAnalysisInfo info = infos.get(i-1);
            WebMonInvalidAnalysisInfoDto dto =new WebMonInvalidAnalysisInfoDto();
            dto.setNum(i);
            dto.setReason(info.getReason());
            dto.setFmcount(info.getFmcount());
            dto.setSyxxcount(info.getSyxxcount());
            dto.setWgsjcount(info.getWgsjcount());
            dto.setTotal(info.getTotal());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebExpiryNoticeInfoDto> getWebExpiryNoticeInfoDto(List<WebExpiryNoticeInfo> infos) {
        List<WebExpiryNoticeInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebExpiryNoticeInfo info = infos.get(i-1);
            WebExpiryNoticeInfoDto dto =new WebExpiryNoticeInfoDto();
            dto.setNum(i);
            dto.setPatNum(info.getPatNum());
            dto.setApplyPersonLast(info.getApplyPersonLast());
            dto.setPatName(info.getPatName());
            dto.setPatTypeName(info.getPatType());
            dto.setExpiryDate(info.getExpiryDate());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebApplyChangeInfoDto> getWebApplyChangeInfoDto(List<WebApplyChangeInfo> infos) {
        List<WebApplyChangeInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebApplyChangeInfo info = infos.get(i-1);
            WebApplyChangeInfoDto dto =new WebApplyChangeInfoDto();
            dto.setNum(i);
            dto.setPatNum(info.getPatNum());
            dto.setPatName(info.getPatName());
            dto.setPatAddressPrevious(info.getPatAddressPrevious());
            dto.setApplyPersonPrevious(info.getApplyPersonPrevious());
            dto.setApplyPersonLast(info.getApplyPersonLast());
            dto.setPatName(info.getPatName());
            dto.setDateLast(info.getDateLast());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebInvalidAnalysisInfoDto> getWebInvalidAnalysisInfoDto(List<WebInvalidAnalysisInfo> infos) {
        List<WebInvalidAnalysisInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            WebInvalidAnalysisInfo info = infos.get(i-1);
            WebInvalidAnalysisInfoDto dto =new WebInvalidAnalysisInfoDto();
            dto.setNum(i);
            dto.setPatNum(info.getPatNum());
            dto.setApplyPersonLast(info.getApplyPersonLast());
            dto.setPatName(info.getPatName());
            dto.setPatTypeName(info.getPatTypeName());
            dto.setExpiryDate(info.getExpiryDate());
            dto.setEffectReason(info.getEffectReason());
            dto.setMaintenanceYear(info.getMaintenanceYear());
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<WebPacApplicantInfoDto> getWebPacApplicantInfoDto(List<PacApplicantInfo> infos) {
        List<WebPacApplicantInfoDto> dtos = new ArrayList<>();
        for (int i = 1;i<=infos.size();i++){
            PacApplicantInfo info = infos.get(i-1);
            WebPacApplicantInfoDto dto =new WebPacApplicantInfoDto();
            dto.setNum(i);
            dto.setApplicantName(info.getApplicantName());
            dto.setApplicantType(info.getApplicantType());
            dto.setAddress(info.getAddress());
            dto.setAreaName(info.getAreaName());
            dto.setIndustryName(info.getIndustryName());
            dtos.add(dto);
        }
        return dtos;
    }

    /**
     * 上传统计报表到文件服务器后返回文件标识
     */
    @Override
    public String exportAnalysisReport(Integer platformId) throws Exception{
        String filename = WebExcelUtils.getUUID();
        File file = new File(WebExcelUtils.getNewFilePath(platformId,filename)+".xls");
        FileOutputStream out = new FileOutputStream(file);
        HSSFWorkbook book = WebExcelUtils.getAnalysisReportBook();

        //sheet1
        ExcelWriter sheet1Writer = new ExcelWriter(book,"工作进程表");
        exportSheet1(sheet1Writer,out,platformId);
        //sheet2
        ExcelWriter sheet2Writer = new ExcelWriter(book,"统计分析");
        exportSheet2(sheet2Writer,out,platformId);
//        exportSheet2(sheet1Writer2,out,platformId);
        //sheet3
        ExcelWriter sheet3Writer = new ExcelWriter(book,"代理机构统计");
        exportSheet3(sheet3Writer,out,platformId);
        //sheet4
        ExcelWriter sheet4Writer = new ExcelWriter(book,"权利人统计");
        exportSheet4(sheet4Writer,out,platformId);
        //sheet5
        ExcelWriter sheet5Writer = new ExcelWriter(book,"监控汇总");
        exportSheet5(sheet5Writer,out,platformId);
        //sheet6
        ExcelWriter sheet6Writer = new ExcelWriter(book,"监控分析");
        exportSheet6(sheet6Writer,out,platformId);
        out.flush();
        out.close();
        return filename;
    }




    /**
     * sheet导出
     */
    private void exportSheet1(ExcelWriter sheet1Writer, FileOutputStream out,Integer platformId) {
        // 合并单元格后的标题行，使用默认标题样式
        CellStyle headCellStyle = sheet1Writer.getHeadCellStyle();
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheet1Writer.merge(14, DateUtils.getCurrentYear()+"年万人专利授权指数进程表");
        sheet1Writer.merge(14, "统计日期："+DateUtils.dateformat(new Date()));
        sheet1Writer.writeRow(CollUtil.newArrayList("区域",
                "一月份","二月份","三月份","四月份","五月份","六月份","七月份",
                "八月份","九月份","十月份","十一月份","十二月份","目标","完成率"));
        //数据
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getWRPatAuthorizeByYear(platformId, 1);
        List<List<Object>> rows = getRptPatentDataAreaInfoArray(infos);
        sheet1Writer.write(rows);
        sheet1Writer.setCurrentRow( sheet1Writer.getCurrentRow()+3);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheet1Writer.merge(14, DateUtils.getCurrentYear()+"年万人发明专利授权指数进程表");
        sheet1Writer.merge(14, "统计日期："+DateUtils.dateformat(new Date()));
        sheet1Writer.writeRow(CollUtil.newArrayList("区域",
                "一月份","二月份","三月份","四月份","五月份","六月份","七月份",
                "八月份","九月份","十月份","十一月份","十二月份","目标","完成率"));
        List<RptPatentDataAreaInfo> fminfo = rptPatentDataAreaService.getWRIpatAuthorizeByYear(platformId, 1);
        List<List<Object>> fmrows = getRptPatentDataAreaInfoArray(fminfo);
        sheet1Writer.write(fmrows);
    }
    private void exportSheet2(ExcelWriter sheetWriter, FileOutputStream out,Integer platformId) {
        // 合并单元格后的标题行，使用默认标题样式
        CellStyle headCellStyle = sheetWriter.getHeadCellStyle();
        CellStyle cellStyle = sheetWriter.getCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(5, DateUtils.getCurrentYear()+"授权专利年度统计");
        sheetWriter.merge(5, "统计日期："+DateUtils.dateformat(new Date()));
        sheetWriter.writeRow(CollUtil.newArrayList("年份",
                "发明（件）","实用新型（件）","外观设计（件）","合计（件）","年增长率"));
        //数据
        List<WebYearStatisticInfo> trendAnalysisList = rptPatentDataAreaService.getTrendAnalysisList(platformId, 1);
        List<List<Object>> rows = getTrendAnalysisList(trendAnalysisList);
        sheetWriter.write(rows);

        sheetWriter.setCurrentRow( sheetWriter.getCurrentRow()+3);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(4, DateUtils.getCurrentYear()+"有效专利区域统计");
        sheetWriter.merge(4, "统计日期："+DateUtils.dateformat(new Date()));
        sheetWriter.writeRow(CollUtil.newArrayList("所属区域","发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
        //rows
        List<WebAreaStatisticInfo> yxcount = rptPatentDataAreaService.getAreaAnalysislList(platformId, "", "");
        List<List<Object>> yxrows = getWebAreaStatisticInfoArray(yxcount);
        sheetWriter.write(yxrows);

        sheetWriter.setCurrentRow( sheetWriter.getCurrentRow()+3);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(4, DateUtils.getCurrentYear()+"有效专利IPC分类统计");
        sheetWriter.merge(4, "统计日期："+DateUtils.dateformat(new Date()));
        sheetWriter.writeRow(CollUtil.newArrayList("IPC分类","发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
        //rows
        List<WebIPCAnalysisInfo> infos = rptPatentDataAreaService.getIPCAnalysisList(platformId, "", "");
        List<List<Object>> ipcrows = getWebIPCAnalysisInfoArray(infos);
        sheetWriter.write(ipcrows);
//        sheetWriter.flush(out);
//        sheetWriter.close();
    }
    private void exportSheet3(ExcelWriter sheetWriter, FileOutputStream out, Integer platformId) {
        // 合并单元格后的标题行，使用默认标题样式
        CellStyle headCellStyle = sheetWriter.getHeadCellStyle();
        CellStyle cellStyle = sheetWriter.getCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(5, DateUtils.getCurrentYear()+"代理机构统计");
        sheetWriter.merge(5, "统计日期："+DateUtils.dateformat(new Date()));
        List<WebAgencyAnalysisInfo> infos = rptPatentDataAreaService.getAgencyAnalysislAllList(platformId,2);
        sheetWriter.merge(5, "代理机构共"+infos.size()+"家");
        List<List<Object>> fmrows = getWebAgencyAnalysisInfoArray(infos);
        sheetWriter.writeRow(CollUtil.newArrayList("代理机构", "权利人（个）","发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
        sheetWriter.write(fmrows);

    }
    private void exportSheet4(ExcelWriter sheetWriter, FileOutputStream out, Integer platformId) {
        // 合并单元格后的标题行，使用默认标题样式
        CellStyle headCellStyle = sheetWriter.getHeadCellStyle();
        CellStyle cellStyle = sheetWriter.getCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(6, DateUtils.getCurrentYear()+"权力人统计");
        sheetWriter.merge(6, "统计日期："+DateUtils.dateformat(new Date()));
        SearchApplicantAnalysisParam param = new SearchApplicantAnalysisParam();
        param.setPageNumber(1);
        param.setPageSize(5000);
        PageResult<WebApplicantInfo> infos = rptApplicantService.getApplicantAnalysisList(platformId, param);
        if (infos != null && infos.getItems() !=null &&infos.getItems().size() >0){
            sheetWriter.merge(5, "权力人共"+infos.getItems().size()+"个");
            List<List<Object>> fmrows = getWebApplicantInfoArray(infos.getItems());
            sheetWriter.writeRow(CollUtil.newArrayList("权利人", "区域","行业","发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
            sheetWriter.write(fmrows);
        }
//        sheetWriter.flush(out);
//        sheetWriter.close();
    }
    private void exportSheet5(ExcelWriter sheetWriter, FileOutputStream out, Integer platformId) {
        // 合并单元格后的标题行，使用默认标题样式
        CellStyle headCellStyle = sheetWriter.getHeadCellStyle();
        CellStyle cellStyle = sheetWriter.getCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(5, DateUtils.getCurrentYear()+"监控汇总");
        sheetWriter.merge(5, "统计日期："+DateUtils.dateformat(new Date()));
        List<WebAgencyAnalysisInfo> infos = rptPatentDataAreaService.getAgencyAnalysislAllList(platformId,2);
        WebPlatformEntity webPlatformEntity = webPlatformService.queryById(platformId);
        Integer expiredmonths = webPlatformEntity.getExpiredmonths();
        if (expiredmonths == null) expiredmonths =1;
        sheetWriter.writeRow(CollUtil.newArrayList("将来"+ expiredmonths +"个月即将过年费缴纳期","今年专利权转入","今年专利权转出","今年专利失效"));
        WebMonSummaryExportinfo sumInfo = pacPatentinfoService.getMonSummaryExportinfo(webPlatformEntity);//汇总信息
        List<Object> fmrows = getWebMonSummaryExportinfoArray(sumInfo);
        sheetWriter.write(fmrows);
        sheetWriter.writeRow(CollUtil.newArrayList("权利人","类别","即将届满","专利权转入","专利权转出","专利失效"));
        SearchMonSummaryParam param = new SearchMonSummaryParam();
        param.setPageNumber(1);
        param.setPageSize(5000);
        PageResult<WebMonSummaryInfo> result = pacPatentinfoService.queryList(param, platformId);
        if (result != null && result.getItems() != null && result.getItems().size() > 0){
            List<List<Object>> wsinfo = getWebMonSummaryInfoArray(result.getItems());
            sheetWriter.write(wsinfo);
        }
    }
    private void exportSheet6(ExcelWriter sheetWriter, FileOutputStream out, Integer platformId) {
        // 合并单元格后的标题行，使用默认标题样式
        CellStyle headCellStyle = sheetWriter.getHeadCellStyle();
        CellStyle cellStyle = sheetWriter.getCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(4, "今年专利权转入");
        sheetWriter.merge(4, "统计日期："+DateUtils.dateformat(new Date()));
        sheetWriter.writeRow(CollUtil.newArrayList("所属区域",
                "发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
        //数据
        List<WebMonAnalysisInfo> inInfos = pacPatentinfoService.getInList(platformId, "", "");
        List<List<Object>> inrows = getWebMonAnalysisInfoArray(inInfos);
        sheetWriter.write(inrows);

        sheetWriter.setCurrentRow( sheetWriter.getCurrentRow()+3);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(4, DateUtils.getCurrentYear()+"今年专利权转出");
        sheetWriter.merge(4, "统计日期："+DateUtils.dateformat(new Date()));
        sheetWriter.writeRow(CollUtil.newArrayList("所属区域","发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
        List<WebMonAnalysisInfo> outInfos = pacPatentinfoService.geOutList(platformId, "", "");
        List<List<Object>> outrows = getWebMonAnalysisInfoArray(outInfos);
        sheetWriter.write(outrows);

        sheetWriter.setCurrentRow( sheetWriter.getCurrentRow()+3);
        headCellStyle.setAlignment(HorizontalAlignment.RIGHT);//水平居中
        sheetWriter.merge(4, DateUtils.getCurrentYear()+"专利失效");
        sheetWriter.merge(4, "统计日期："+DateUtils.dateformat(new Date()));
        sheetWriter.writeRow(CollUtil.newArrayList("失效原因","发明（件）","实用新型（件）","外观设计（件）","合计（件）"));
        List<WebMonInvalidAnalysisInfo> invalidInfos = pacPatentinfoService.geInvalidList(platformId, "", "");
        List<List<Object>> invalidrows = getWebMonInvalidAnalysisInfoArray(invalidInfos);
        sheetWriter.write(invalidrows);
        sheetWriter.flush(out);
        sheetWriter.close();
    }


    private List<Object> getWebMonSummaryExportinfoArray(WebMonSummaryExportinfo infos) {
        if (infos == null) return new ArrayList<>();
        ArrayList<Object> objects = CollUtil.newArrayList(
                infos.getExpiryInfo(),
                infos.getInInfo(),
                infos.getOutInfo(),
                infos.getExpiryInfo()
        );
        return objects;
    }
    private List<List<Object>> getTrendAnalysisList(List<WebYearStatisticInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebYearStatisticInfo info :infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getYear(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal(),
                    info.getIncreaseRate() == null ? "0%" :info.getIncreaseRate()+"%"
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getRptPatentDataAreaInfoArray(List<RptPatentDataAreaInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (RptPatentDataAreaInfo info :infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getAreaName(),
                    info.getJan(),
                    info.getFeb(),
                    info.getMar(),
                    info.getApr(),
                    info.getMay(),
                    info.getJune(),
                    info.getJuly(),
                    info.getAug(),
                    info.getSetp(),
                    info.getOct(),
                    info.getNov(),
                    info.getDec(),
                    info.getGoal(),
                    info.getCompletionRate()+"%"
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebIPCAnalysisInfoArray(List<WebIPCAnalysisInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebIPCAnalysisInfo info : infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getIpcName(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal()
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebAreaStatisticInfoArray(List<WebAreaStatisticInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebAreaStatisticInfo info : infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getAreaName(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal()
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebAgencyAnalysisInfoArray(List<WebAgencyAnalysisInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebAgencyAnalysisInfo info : infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getAgencyName(),
                    info.getApplicantCount(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal()
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebApplicantInfoArray(List<WebApplicantInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebApplicantInfo info : infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getApplicantName(),
                    info.getAreaName(),
                    info.getIndustry(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal()
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebMonAnalysisInfoArray(List<WebMonAnalysisInfo> inInfos) {
        List<List<Object>> result = new ArrayList<>();
        if (inInfos == null || inInfos.size()< 0) return result;
        for (WebMonAnalysisInfo info : inInfos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getAreaName(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal()
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebMonInvalidAnalysisInfoArray(List<WebMonInvalidAnalysisInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebMonInvalidAnalysisInfo info : infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getReason(),
                    info.getFmcount(),
                    info.getSyxxcount(),
                    info.getWgsjcount(),
                    info.getTotal()
            );
            result.add(objects);
        }
        return result;
    }
    private List<List<Object>> getWebMonSummaryInfoArray(List<WebMonSummaryInfo> infos) {
        List<List<Object>> result = new ArrayList<>();
        if (infos == null || infos.size()< 0) return result;
        for (WebMonSummaryInfo info : infos) {
            ArrayList<Object> objects = CollUtil.newArrayList(
                    info.getName(),
                    info.getType(),
                    info.getJmCount(),
                    info.getZrCount(),
                    info.getZcCount(),
                    info.getSxCount()
            );
            result.add(objects);
        }
        return result;
    }

}
